﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">体测档案</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <span class="k-textbox k-space-right">
                <input type="text" placeholder="请输入档案名称" id="txtKey" />
                <a href="javascript:Filters()" class="k-icon k-i-search">&nbsp;</a>
            </span>
            <button class="k-button" onclick="CreateNewArchive()"><span class="k-icon k-i-plus"></span><span>添加新档案</span></button>
        </div>
        <div id="grid_archives" style="text-align: center"></div>
    </div>
</div>
<script class="init">
    LocatedMenu("体质健康", "档案管理");
</script>

<script class="grid_archive_columns">
    var archiveFields = [{
        title: "标题",
        field: "Title",
        width: 300
    }, {
        title: "描述",
        field: "Description",
        attributes: { style: "text-align:left; text-indent:2em" },
        width: 400
    }, {
        title: "开始日期",
        field: "BeginTime",
        template: "#=kendo.toString(kendo.parseDate(BeginTime),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "截止日期",
        field: "EndTime",
        template: "#=kendo.toString(kendo.parseDate(EndTime),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "操作",
        template: "#=GetOperations(Guid)#",
        attributes: { style: "text-align:left" }
    }];

    function GetOperations(guid) {
        var html = "<button class='k-button' onclick=\"EditArchive('" + guid + "')\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        //html += "<button class='k-button' onclick=\"DeleteArchive('" + guid + "')\"><span class='k-icon k-i-cancel'></span><span>删除</span></button>";
        return html;
    }

    function EditArchive(guid) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改档案信息" });
            wndGeneralEdit.refresh({ url: "/Achievements/Archive/Edit/" + guid });
            wndGeneralEdit.open();
        }
    }

    function DeleteArchive(guid) {
        if (confirm("真的要删除这个班级吗？")) {
            Whale.Remote.Operation({
                url: "/Achievements/Archive/DeleteArchive",
                parameters: { guid: guid },
                success: function (result) {
                    if ($("#grid_archives").length > 0)
                        $("#grid_archives").data("kendoGrid").dataSource.read();
                },
                error: function (msg) {
                    wndGeneralInformation.content(msg).open();
                }
            });
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_archives").kendoGrid({
            columns: archiveFields,
            dataSource: Whale.dataSource({
                url: "/Achievements/Archive/GetMyArchives",
                getParameters: function () {
                    return {
                        aType:2,
                        key: $.trim($("#txtKey").val()),
                        bureauID: "@PH.Web.Global.WebContext.CurrentUser.AssociatedBureauID"
                    };
                },
                pageSize: 20

            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });

    function CreateNewArchive() {
        wndGeneralEdit.setOptions({ title: "添加新的档案" });
        wndGeneralEdit.refresh({ url: "/Achievements/Archive/Edit" });
        wndGeneralEdit.open();
    }

    function Filters() {
        $("#grid_archives").data("kendoGrid").dataSource.page(0);
    }
</script>

